package com.wudl.java8.lambda;

import com.wudl.java8.bean.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : LambaMethod
 * @Description :  Lamba 方法的使用
 * @Author :wudl
 * @Date: 2021-08-17 22:35
 */

public class LambaMethod {

    public static void main(String[] args) {

        //1.list ForEach 的输出
        LambaMethod.LambaList();
        //2.Map 的输出
        LambaMethod.LambaMap();
        //3. List 集合排序
        LambaMethod.getListSort();
    }

    public static void LambaList()
    {
        System.out.println("-----------------LambaList--------------");

        List<String> list = new ArrayList<String>();
        list.add("java");
        list.add("hive");
        list.add("Flink");

        list.forEach((num) -> {
            System.out.println(num);
        });
    }

    public static void LambaMap()
    {
        System.out.println("-----------------LambaMap--------------");
        Map<String,Object> map = new HashMap<>();
        map.put("java","java-version");
        map.put("hive","hive-version");
        map.put("Flink","Flink-version");

        map.forEach((num,value) -> {
            System.out.println(num +"---"+ value);
        });
    }

    public  static  void  getListSort()
    {
        System.out.println("-----------------getListSort--------------");
        List<User> list = new ArrayList<>();
        list.add(new User("java",18));
        list.add(new User("spark",10));
        list.add(new User("doris",15));
        list.add(new User("flink",20));

        list.sort((key1,value1) ->
            key1.getAge() - value1.getAge()
        );

        list.forEach(value1 ->{
            System.out.println(value1);
        });
    }
}
